<?php
/*
          U1,                                               
          LMF1Yr,                                           
          BOOMBBBBBBq                                       
         7BEP0PNqZBM                                        
         B8kPFXFX0B                                         
        YBXXSSFkSB;     APUXIN
        Bqk1k5SFNZ      Web OS
     :r0Ek5kSXSXO;      
   jBBBNPkXF5uUYF:      by Apuxin Team
  BBqPkXUj7rrr;rrur    
.J8FX5u7r;rr7r7r7rUi    outputbuffer.service.php: Manage the session
0UkkJ7irr7rrr7rrrrrj           
PuX7;i7;r;r;rrririrL.           
 7L;;rrrrriri;i;i;iL           
  YL7;riri;i;iii;iL:  
   ;LLrr;ri;i;irr7.                                         
       ...... .      

*/

/**
* Controls the output
*/

//$_BUFFER = array();

class outputbuffer extends APUXIN_SERVICE
{
    /**
     * The Buffer
     * @var array
     */
    private $buffer = array();

    /**
     * Constructor of the class
     */
    public function __construct()
    {
        parent::__construct();
        $this->info_setName("outputbuffer");
        $this->info_setDesc("Buffers the output");
        $this->info_setVersion(1.0);
        $this->info_setOnlyOnce(true);
        $this->clear();
    }

    /**
     * Destructor of the class
     */
    public function __destruct()
    {
        $this->flush();
    }

    /**
     * @param String to add to the Buffer
     * @return Integer Number of Entries
     */
    public function add()
    {
        if(func_num_args() == 1)
        {
            $this->buffer[] = func_get_arg(0);
            return count($this->buffer)-1;
        }
    }

    /**
     *
     * @param Integer $id ID of the entry
     */
    public function delete($id)
    {
        if(array_key_exists($id, $this->buffer))
        {
            $i = 0;
            $oldbuf = $this->buffer;
            $newbuf = array();
            foreach($oldbuf as $buf)
            {
                if($buf != $oldbuf[$id])
                {
                    $newbuf[$i] = $buf;
                    $i++;
                }
            }
            $this->buffer = $newbuf;
        }
    }

    /**
     * Flushs the Buffer
     */
    public function flush()
    {
        foreach($this->buffer as $buf)
        {
            echo $buf . "\n";
        }
        $this->clear();
    }

    /**
     * Clears the Buffer
     */
    public function clear()
    {
        if(count($this->buffer) > 0)
        {
            $this->buffer = array();
        }
    }
}
?>